package com.imti.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.imti.entity.PatientDot;
import com.imti.entity.Patient;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * (Patient)表数据库访问层
 *
 * @author makejava
 * @since 2023-02-01 08:43:22
 */
@Mapper
public interface PatientDao extends BaseMapper<Patient> {

    /**
     * 根据患者账号查询
     * @param accId
     * @return
     */
    @Select("select pat_name,card_code,pat_sex,pat_birthday,pat_phone,patLive,patAddress from patient where acc_id=#{accId}")
    public Patient findPatByAccId(int accId);

    /**
     * 添加患者
     * @param patient
     * @return
     */
    @Insert("insert into patient(pat_name,card_code,pat_sex,pat_birthday,pat_phone,patLive,patAddress) values(#{patName},#{cardCode},#{patSex},#{patBirthday},#{patPhone},#{patLive},#{patAddress})")
    public int addPat(Patient patient);

    /**
     * 根据患者身份证号查询患者信息和诊疗号
     * @param cardCode
     * @return
     */
    @Select("select pt.pat_name,pt.card_code,pt.pat_sex,pt.pat_birthday,pt.pat_phone,pt.patLive,pt.patAddress,ca.card_num from patient pt,card ca where ca.card_code=pt.card_code and pt.card_code=#{cardCode}")
    public List<PatientDot> getPatCardCode(String cardCode);
}

